/**
 * Created by sunyan on 2017/7/10.
 */
import {chart} from './chart'
import {barChartData} from './barChart'

/*
* 详情层
* doShowLayer： 展示详情层
* doHideLayer： 关闭详情层
* */
import boot from './map'
let layer = {
  showLayer(id){
    var layer = $('#'+id);
    layer.css({'visibility':'visible','display':'block'});
    // $('#content-1').css({'visibility':'visible'});
    $('#tab-1').addClass('tab-current')
    // $('#chartContainer').css({'z-index':10})
    // $('#noticeContainer').css({'z-index':11})

    return this
  },
  hideLayer () {
    $('.hw-overlay').css({'visibility':'hidden','display':'none'});
    $('#content-1').css({'visibility':'hidden'});
    $('#content-2').css({'visibility':'hidden'});
    $('#noticeContainer').css({'display':'block'});
    $('#tab-area').css({'display':'none'});
    $('.tab').removeClass('tab-current')
    $('.g-chart').remove()
    $('#slide-right').empty()
    $('#equipmentValueMin').empty().siblings('.spanMark').css('display','none')
    $('#equipmentValueMin').empty()
    $('#equipmentValueMax').empty().siblings('.spanMark').css('display','none')
    return this
  },
  doShowLayer(){
    $('.hwLayer-ok,.hwLayer-cancel,.hwLayer-close').on('click', function() {
      hideLayer();
    });
    return this
  },
  doHideLayer(){
    $('.hw-overlay').on('click',  function(event) {
      if (event.target == this){
        hideLayer();
      }
    });
    return this
  }
}

/*
 *
 * showEquipmentDetail:点击设备名称，展示该设备相应的详情页，以弹框的形式出现
 * hideEquipmentDetail: 关闭详情层
 * tatContent： 详情层tab切换
 * */
let interaction = {
  showEquipmentDetail(){
    $('#showList').on('click','p',function () {
      var name = $(this).text();
      $('#d_equipment_name').html(name || 'null')
      layer.showLayer('hw-layer')
      chart.insertChart('chart-box-1','chart-1',window.config.mapIp+'/tupu/lifecycle',{name:name});
      chart.insertChart('chart-box-2','chart-2',window.config.mapIp+'/tupu/price',{name:name});
      barChartData(".slide-right",window.config.mapIp+"/tupu/desc?",{name:name},"常见故障");
      barChartData(".slide-right",window.config.mapIp+"/tupu/cas?",{name:name},"常见故障原因");
      boot.initChinaMap(name)
      var promiseTimer = setInterval(function () {
        if(window.config.promiseStep == 5){
          clearInterval(promiseTimer)
          window.config.promiseStep = 0;
          $('#tab-area').css({'display':'block'});
          $('#noticeContainer').css({'display':'none'});
          $('#content-1').css({'visibility':'visible'});
        }
      },100)
      console.log('请求数量：'+window.config.promiseStep)
    })
    return this
  },
  hideEquipmentDetail(){
    $('#close').on('click',function () {
      layer.hideLayer();
    })
    return this
  },
  tatContent(){
    $('#tab-area').find('div.tab').on('click',function () {
      let _this  = $(this);
      let _index = _this.index() + 1;
      _this.addClass('tab-current');
      _this.siblings('div.tab').removeClass('tab-current')
      $('#content-'+_index).css({'z-index':30000,'visibility':'visible'});
      $('#content-'+_index).siblings('div').css({'z-index':20000,'visibility':'hidden'})

    })
  }
}

module.exports = {layer,interaction}

